// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Requests;
using Elastic.Clients.Elasticsearch.Serialization;
using Elastic.Transport;
using Elastic.Transport.Extensions;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.SearchApplication;

public sealed partial class SearchApplicationSearchRequestParameters : RequestParameters
{
	/// <summary>
	/// <para>
	/// Determines whether aggregation names are prefixed by their respective types in the response.
	/// </para>
	/// </summary>
	public bool? TypedKeys { get => Q<bool?>("typed_keys"); set => Q("typed_keys", value); }
}

/// <summary>
/// <para>
/// Run a search application search.
/// Generate and run an Elasticsearch query that uses the specified query parameteter and the search template associated with the search application or default template.
/// Unspecified template parameters are assigned their default values if applicable.
/// </para>
/// </summary>
public sealed partial class SearchApplicationSearchRequest : PlainRequest<SearchApplicationSearchRequestParameters>
{
	public SearchApplicationSearchRequest(Elastic.Clients.Elasticsearch.Name name) : base(r => r.Required("name", name))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.SearchApplicationSearch;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "search_application.search";

	/// <summary>
	/// <para>
	/// Determines whether aggregation names are prefixed by their respective types in the response.
	/// </para>
	/// </summary>
	[JsonIgnore]
	public bool? TypedKeys { get => Q<bool?>("typed_keys"); set => Q("typed_keys", value); }

	/// <summary>
	/// <para>
	/// Query parameters specific to this request, which will override any defaults specified in the template.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("params")]
	public IDictionary<string, object>? Params { get; set; }
}

/// <summary>
/// <para>
/// Run a search application search.
/// Generate and run an Elasticsearch query that uses the specified query parameteter and the search template associated with the search application or default template.
/// Unspecified template parameters are assigned their default values if applicable.
/// </para>
/// </summary>
public sealed partial class SearchApplicationSearchRequestDescriptor : RequestDescriptor<SearchApplicationSearchRequestDescriptor, SearchApplicationSearchRequestParameters>
{
	internal SearchApplicationSearchRequestDescriptor(Action<SearchApplicationSearchRequestDescriptor> configure) => configure.Invoke(this);

	public SearchApplicationSearchRequestDescriptor(Elastic.Clients.Elasticsearch.Name name) : base(r => r.Required("name", name))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.SearchApplicationSearch;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "search_application.search";

	public SearchApplicationSearchRequestDescriptor TypedKeys(bool? typedKeys = true) => Qs("typed_keys", typedKeys);

	public SearchApplicationSearchRequestDescriptor Name(Elastic.Clients.Elasticsearch.Name name)
	{
		RouteValues.Required("name", name);
		return Self;
	}

	private IDictionary<string, object>? ParamsValue { get; set; }

	/// <summary>
	/// <para>
	/// Query parameters specific to this request, which will override any defaults specified in the template.
	/// </para>
	/// </summary>
	public SearchApplicationSearchRequestDescriptor Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		ParamsValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ParamsValue is not null)
		{
			writer.WritePropertyName("params");
			JsonSerializer.Serialize(writer, ParamsValue, options);
		}

		writer.WriteEndObject();
	}
}